package com.cleanly.boot.service;

import com.cleanly.boot.dao.UserDao;
import com.cleanly.boot.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wangyupeng
 * @despriction:
 * @ate:Created in 19:29 2019/1/14
 * @modify By:
 */
@Service
@Slf4j
public class UserService {
    @Resource
    private UserDao userDao;

    public List<String> test(){
        log.info("进入test方法");
        return userDao.test();
    }

    public List<User> queryInfo(){
        log.info("进入queryInfo方法");
        return userDao.queryUserInfo();
    }

    public User getInfo(User user) {
        log.info("进入getInfo方法");
        if ("".equals(user.getUserId()) || null==user.getUserId()) {
            log.error("UserId不允许为空");
        }
        return userDao.getInfo(user);
    }

    public int addUser(User user) {
        log.info("进入addUser方法");
        return userDao.addUser(user);
    }

    public int deleteUser(User user) {
        log.info("进入deleteUser方法");
        return userDao.deleteUser(user);
    }

    public int updateUser(User user) {
        //修改之前先要查询
        User userInfo =  userDao.getInfo(user);
        userInfo.setUserId(user.getUserId());
        userInfo.setPassword(user.getPassword());
        userInfo.setPhoneNum(user.getPhoneNum());
        userInfo.setUsername(user.getUsername());
        return userDao.updateUser(userInfo);
    }

    public Integer login(User user){
        Integer num = userDao.login(user);
        log.info("查询结果num:"+num);
        if(num == null || num == 0){
            log.info("用户名或者密码输入错误！");
            return 0;
        }
        return num;
    }
}
